<?php
/**
 * Created by PhpStorm.
 * User: m1514
 * Date: 2017/1/6
 * Time: 21:53
 */

namespace Home\Controller;


use Common\Model\CommodityModel;

class OrderController extends HomeQController
{
    public function index(){
        $conf=[
            'js'=>['list','account']
        ];
        $this->assign('conf',$conf);
        $confData=[
            'css'=>['account']
        ];
        $this->assign('confData',$confData);
        if(IS_POST){
            if(!isset($_POST['sid'])){
                $this->error('请选择要下单的商品');die;
            }
            $sids=I('post.sid');
//            dd($sids);die;
            $data=[];
            foreach($sids as $k=>$sid){
                $data['order'][$sid]=$_SESSION['cart']['goods'][$sid];
                $data['order'][$sid]['pic']=(new CommodityModel())->where("gid={$sid['id']}")->getField('pic');

            }
            $data['total']=0;
            $data['total_rows']=0;
            foreach($data['order'] as $k=>$v){
                $data['total']=$data['total']+$v['total'];
                $data['total_rows']=$data['total_rows']+$v['num'];
            }
            $_SESSION['order']=$data;
            redirect(u('index'));die;

        }
        //显示模板
        $this->display();
    }
}